var net = require("net");
var server = net.createServer();
server.listen(3323,()=>{
    console.log("服务器已启动");
});
//创建客户端口
// net.createConnection(3323);

server.maxConnections=5;

server.on("connection",(socket)=>{
    console.log("ip地址 "+socket.remoteAddress);
    console.log("端口地址 "+socket.remotePort);
    server.getConnections((err,count)=>{
        console.log("已连接人数 ",count);
    });
    socket.on("close",()=>{
        server.getConnections((err,count)=>{
            console.log("退出1人");
            console.log("已连接人数 ",count);
        });
    })
    //发送
    process.stdin.on("data",(data)=>{
        socket.write(data);
    });
    //接收
    socket.on("data",(data)=>{
        console.log(data.toString().trim());
    });
});
server.on("listening",()=>{
    console.log("正常连接");
});
server.on("close",()=>{
    console.log("服务器关闭");
})